# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=pentestgpt
pkgver=v0.14.0.r7.g0f8e73a
pkgrel=4
pkgdesc='A penetration testing tool empowered by ChatGPT. It is designed to automate the penetration testing process.'
groups=('blackarch' 'blackarch-automation')
arch=('any')
url='https://github.com/GreyDGL/PentestGPT'
license=('MIT')
depends=('python' 'python-virtualenv' 'cargo')
makedepends=('git')
source=("$pkgname::git+https://github.com/GreyDGL/PentestGPT.git")
sha512sums=(SKIP)
install="$pkgname.install"

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

package() {
  cd $pkgname

	install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" *.md
  install -Dm 644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm *.md

  cp -a * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
source /usr/share/$pkgname/venv/bin/activate
exec python ./$pkgname/main.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

